package net.pierrerenaudin.blobbyvolley.client;

import com.google.gwt.dom.client.MediaElement;
import com.google.gwt.media.client.Audio;

public class SoundManager {

	private boolean mute;

	private String touchPath = "data/audio/touch.ogg";
	private Audio touchAudio;

	private String whistlePath = "data/audio/whistle.ogg";
	private Audio whistleAudio;

	public SoundManager(){
		touchAudio = Audio.createIfSupported();
		touchAudio.getAudioElement().setSrc(touchPath);
		touchAudio.getAudioElement().setPreload(MediaElement.PRELOAD_AUTO);
		touchAudio.getAudioElement().load();
		
		whistleAudio = Audio.createIfSupported();
		whistleAudio.getAudioElement().setSrc(whistlePath);
		whistleAudio.getAudioElement().setPreload(MediaElement.PRELOAD_AUTO);
		whistleAudio.getAudioElement().load();
	}

	public void playTouch(){
		if(!mute){
			touchAudio.getAudioElement().play();
			touchAudio.getAudioElement().setCurrentTime(0);
		}
	}

	public void playWhistle(){
		if(!mute){
			whistleAudio.getAudioElement().play();
			whistleAudio.getAudioElement().setCurrentTime(0);
		}
	}

	public void setMute(boolean mute) {
		this.mute = mute;
	}

	public boolean isMute() {
		return mute;
	}

}
